<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="100px">
      <!-- 需要隐藏的项上使用属性  v-show="showSearch" -->
      <el-form-item label="单位名称" prop="orgName">
        <el-input
          v-model="queryParams.orgName"
          style="width: 232px"
          maxlength="30"
          placeholder="请输入单位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="企业前缀" prop="entPrefix">
        <el-input
          v-model="queryParams.entPrefix"
          style="width: 232px"
          maxlength="30"
          placeholder="请输入企业前缀"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="所属二级节点" prop="entPrefix">
        <el-select v-model="queryParams.tagNodeName" placeholder="请选择所属二级节点" filterable clearable style="width: 232px">
          <el-option
            v-for="item in tagNodeList"
            :key="item.tagNodeName"
            :label="item.tagNodeName"
            :value="item.tagNodeName"
          />
        </el-select>
      </el-form-item>
      <el-form-item class="search">
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-content">
      <el-table
        v-loading="loading"
        :data="entbasicinfoList"
        class="table-fixed"
      >
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column type="index" label="序号" width="55" align="center" />
        <!--        <el-table-column label="二级节点id"  align="center" prop="id" v-if="true" show-overflow-tooltip/>-->
        <el-table-column label="单位名称" align="center" prop="orgName" show-overflow-tooltip />
        <el-table-column label="企业前缀" align="center" prop="entPrefix" show-overflow-tooltip />
        <el-table-column label="所属二级节点" align="center" prop="tagNodeName" show-overflow-tooltip />
        <el-table-column label="联系人姓名" align="center" prop="contactName" show-overflow-tooltip />
        <el-table-column label="联系人手机号" align="center" prop="contactPhone" show-overflow-tooltip />
        <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100" fixed="right">
          <template slot-scope="scope">
            <el-button
              v-hasPermi="['business:entbasicinfo:view']"
              size="mini"
              icon="el-icon-view"
              @click="handleView(scope.row)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- 添加、查看、修改企业资质信息对话框 -->
    <el-dialog title="企业信息" class="dialog" :visible.sync="open" width="900px" append-to-body :close-on-click-modal="false">
      <el-radio-group v-model="dialogStep">
        <el-radio-button label="0">单位信息</el-radio-button>
        <el-radio-button label="1">法人信息</el-radio-button>
        <el-radio-button label="2">联系人信息</el-radio-button>
        <el-radio-button label="3">账户信息</el-radio-button>
      </el-radio-group>
      <div v-if="dialogStep === '0'" class="steps">
        <el-divider content-position="left">必填项</el-divider>
        <el-descriptions title="" :column="2">
          <el-descriptions-item label="企业前缀">{{ form.entPrefix }}</el-descriptions-item>
          <el-descriptions-item label="单位名称">{{ form.orgName }}</el-descriptions-item>
          <el-descriptions-item label="单位证件类型">
            {{ getDictLabel(dict.type.org_crt_type, form.orgCrtType) }}
          </el-descriptions-item>
          <el-descriptions-item label="单位性质">
            {{ getDictLabel(dict.type.org_nature, form.orgNature) }}
          </el-descriptions-item>
          <el-descriptions-item label="单位证件号">{{ form.orgCrtCode }}</el-descriptions-item>
          <el-descriptions-item label="行业类型" :span="2">
            {{ getDictLabel(dict.type.industry_category, form.industryCategory) }}/
            {{ getDictLabel(dict.type.industry_specific, form.industrySpecific) }}
          </el-descriptions-item>
          <el-descriptions-item label="单位地址" :span="2">
            {{ getDictLabel(dict.type.province, form.orgAddrProvince) }}
            {{ getDictLabel(dict.type.city, form.orgAddrCity) }}
            {{ getDictLabel(dict.type.district, form.orgAddrCounty) }}
            {{ form.orgAddr }}
          </el-descriptions-item>
          <!-- <el-descriptions-item label="详细地址">
            {{ form.orgAddr }}
          </el-descriptions-item> -->
          <el-descriptions-item label="营业执照照片">
            <el-image
              style="width: 120px;"
              :src="form.orgCrtImg"
              :preview-src-list="[form.orgCrtImg]"
            >
            </el-image>
          </el-descriptions-item>
        </el-descriptions>
        <el-divider content-position="left">非必填项</el-divider>
        <el-descriptions title="" :column="2">
          <el-descriptions-item label="成立时间">{{ form.establishDate || '-' }}</el-descriptions-item>
          <el-descriptions-item label="有效期">{{ form.periodValidity || '-' }}</el-descriptions-item>
          <el-descriptions-item label="注册资本">{{ form.regCapital || '-' }}万元</el-descriptions-item>
          <el-descriptions-item label="注册机关">{{ form.regAuthority || '-' }}</el-descriptions-item>
          <el-descriptions-item label="官方网站">{{ form.website || '-' }}</el-descriptions-item>
          <el-descriptions-item label="单位简介">{{ form.orgDesc || '-' }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div v-if="dialogStep === '1'" class="steps">
        <el-divider content-position="left">必填项</el-divider>
        <el-descriptions title="" :column="2">
          <el-descriptions-item label="法人证件照片正面">
            <el-image
              style="width: 120px;"
              :src="form.legalCrtFrontImg"
              :preview-src-list="[form.legalCrtFrontImg]"
            >
            </el-image>
          </el-descriptions-item>
          <el-descriptions-item label="法人证件照片反面">
            <el-image
              style="width: 120px;"
              :src="form.legalCrtBackImg"
              :preview-src-list="[form.legalCrtBackImg]"
            >
            </el-image>
          </el-descriptions-item>
          <el-descriptions-item label="法人姓名">{{ form.legalName }}</el-descriptions-item>
          <el-descriptions-item label="单位证件类型">
            {{ getDictLabel(dict.type.contact_crt_type, form.legalCrtType) }}
          </el-descriptions-item>
          <el-descriptions-item label="法人证件号">{{ form.legalCrtNo }}</el-descriptions-item>
        </el-descriptions>
        <el-divider content-position="left">非必填项</el-divider>
        <el-descriptions title="" :column="2">
          <el-descriptions-item label="法人手机号">{{ form.legalPhone || '-' }}</el-descriptions-item>
          <el-descriptions-item label="法人传真">{{ form.legalFax || '-' }}</el-descriptions-item>
          <el-descriptions-item label="法人邮箱">{{ form.legalEmail || '-' }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div v-if="dialogStep === '2'" class="steps">
        <el-divider content-position="left">必填项</el-divider>
        <el-descriptions title="" :column="2">
          <el-descriptions-item label="联系人证件照正面">
            <el-image
              v-if="form.contactCrtFrontImg"
              style="width: 120px;"
              :src="form.contactCrtFrontImg"
              :preview-src-list="[form.contactCrtFrontImg]"
            >
            </el-image>
            <span v-else>-</span>
          </el-descriptions-item>
          <el-descriptions-item label="联系人证件照反面">
            <el-image
              v-if="form.contactCrtBackImg"
              style="width: 120px;"
              :src="form.contactCrtBackImg"
              :preview-src-list="[form.contactCrtBackImg]"
            >
            </el-image>
            <span v-else>-</span>
          </el-descriptions-item>
          <el-descriptions-item label="联系人姓名">{{ form.contactName }}</el-descriptions-item>
          <el-descriptions-item label="联系人证件类型">
            {{ getDictLabel(dict.type.contact_crt_type, form.contactCrtType) }}
          </el-descriptions-item>
          <el-descriptions-item label="联系人证件号">{{ form.contactCrtNo }}</el-descriptions-item>
          <el-descriptions-item label="联系人手机号">{{ form.contactPhone }}</el-descriptions-item>
          <el-descriptions-item label="联系人邮箱">{{ form.contactEmail }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div v-if="dialogStep === '3'" class="steps">
        <el-divider content-position="left">必填项</el-divider>
        <el-descriptions title="" :column="1">
          <el-descriptions-item label="用户名">{{ form.bsSysuserVo.userName }}</el-descriptions-item>
          <el-descriptions-item label="手机号码">{{ form.bsSysuserVo.mobile }}</el-descriptions-item>
          <el-descriptions-item label="邮箱">{{ form.bsSysuserVo.email }}</el-descriptions-item>
          <el-descriptions-item label="密码">{{ form.bsSysuserVo.realPass }}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" size="mini" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEntbasicinfo, getEntbasicinfo } from "@/api/business/entbasicinfo";
import {listTagNode} from "@/api/business/tagNode";

export default {
  name: "Entbasicinfo",
  dicts: ["province", "city", "district", "industry_category", "industry_specific", "org_nature", "org_crt_type", "contact_crt_type"],
  data() {
    return {
      // 租户
      tenantList: [],
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 二级节点
      tagNodeList: [],
      // 企业资质信息表格数据
      entbasicinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 详情弹框步骤
      dialogStep: "0",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgName: undefined,
        entPrefix: undefined,
        tagNodeName: undefined
      },
      // 表单参数
      form: {
        bsSysuserVo: {}
      }
    };
  },
  created() {
    this.getTagNodeList();
    this.getList();
  },
  methods: {
    getDictLabel(list, value) {
      if (list.length && value) {
        const item = list.find(item => item.value == value)
        return item.label
      }
    },
    /** 查询所有二级节点 */
    getTagNodeList() {
      this.loading = true;
      listTagNode().then(response => {
        this.tagNodeList = response.rows;
        console.log(this.tagNodeList)
        this.loading = false;
      })
    },
    /** 查询企业资质信息列表 */
    getList() {
      this.loading = true;
      listEntbasicinfo(this.queryParams).then(response => {
        this.entbasicinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        bsSysuserVo: {}
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.tagNodeName = undefined;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getEntbasicinfo(id)
        .then(response => {
          this.form = response.data;
          this.open = true;
        })
        .finally(() => {
          this.loading = false;
        })
    }
  }
};
</script>
<style lang="scss" scoped>
.table-fixed {
  ::v-deep .el-table__fixed-right {
    height: 100% !important; //设置高优先，以覆盖内联样式
  }
  ::v-deep .el-table__fixed {
    height: 100% !important; //设置高优先，以覆盖内联样式
  }
}
.dialog {
  .steps {
    padding: 0 10px;
  }
}
</style>
